#!/usr/bin/env python3
# Created by han on 2016/7/6
import os
import hashlib


def get_file_md5(filename):
    if not os.path.isfile(filename):
        return
    myhash = hashlib.md5()
    with open(filename, "rb") as file:
        while True:
            b = file.read(8096)
            if not b:
                break
            myhash.update(b)
    return myhash.hexdigest()


def dir_size(path):
    """
    获取目录的大小
    :param path:
    :return:
    """
    a = os.walk(path)
    size = 0
    for root, dirs, files in a:
        size += sum([os.path.getsize(os.path.join(root, name)) for name in files])
    return size


